package com.ruoyi.web.core.config;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.UtilTool;
import com.ruoyi.system.service.CommoneService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.concurrent.TimeUnit;

/**
 * @author jiebin
 * @date 2021/8/3 11:10
 */
@Data
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class CateNumberTask {

    @Autowired
    private RedisCache redisCache;
    @Autowired
    private CommoneService commoneService;
    String key = "CateNumberTask";

    //3.添加定时任务
    @Scheduled(cron = "0/10 * * * * ?")
    //或直接指定时间间隔，例如：10秒
    //@Scheduled(fixedRate=1000)
    private void configureTasks() {
        Object msg = redisCache.getCacheObject(key);
        if (!UtilTool.isNull(msg)){
                commoneService.updateWebCateNum();
                redisCache.deleteObject(key);
        }
    }


}
